    $(document).ready(function(){
    	//$("#password").val("123456");
    	clearerror();
    });
    function clearerror(){
    	$("#loginError").html("");
    }
    document.onkeydown = function(e){
        var event = e || window.event;  
        var code = event.keyCode || event.which || event.charCode;
        if (code == 13) {
            login();
        }
    }
    $(function(){
        $("input[name='login']").focus();
    });
    function cleardata(){
        $('#loginForm').form('clear');
        $("#showMsg").html("");
    }

    
    function login(){
        $("#loginError").html("");
    	var name = $("input[name='login']").val();
    	var password = $("input[name='password']").val();
        if(name=="" || password==""){
        	 $("#loginError").html("请输入账号密码!");
             $("input[name='login']").focus();
        }else{
            $("#loginBtnId").attr("disabled", true);
             $.ajax({
                type:"post",
                url:basePath + "login",
                data:{
                	loginName:name,
                	password:password
                },
                cache:false,
                dataType: "json", //this is important
                 beforeSend: ajaxLoading,
                 success:function(result) {
                     ajaxLoadEnd();
                     $("#loginBtnId").attr("disabled", false);
                	if(result.result == "false"){
                		$("#loginError").html("账号或密码错误!");
                	}else{
                        $("#loginError").html("");
                		localStorage.setItem("token",result.token);
                		localStorage.setItem("refreshToken",result.refreshToken);
                        localStorage.setItem("expireTime",result.expireTime);
                        localStorage.setItem("weather",result.weather);
                        localStorage.setItem("username",result.username);
                        localStorage.setItem("logout","false");
                		window.location.href = basePath + "index";
                	}
                }
            });
            //setBtnAvaible("loginId");
        }
    }


